package com.majie.annotation;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.StandardMethodMetadata;

public class MyConditional implements Condition {
	@Override
	public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
		StandardMethodMetadata standardMethodMetadata = ((StandardMethodMetadata) annotatedTypeMetadata);

		//如果根据配置文件是否配置来实例化：
//		Environment evn = conditionContext.getEnvironment();

		//如果需要某个bean是否存在来实例化：
//		boolean contains = conditionContext.getBeanFactory().containsBean("abcBean");
		return standardMethodMetadata.getMethodName().equals("one");
	}
}